const peer = require('./peer-control.ts');
let video = document.getElementById('screen');
peer.on('add-stream', (stream) => {
  play(stream);
});

function play(stream) {
  video.srcObject = stream;
  video.onloadedmetadata = function () {
    video.play();
  };
}

//监听键盘输入
window.onkeydown = function(e){
  console.log('键盘点击',e)
  //data{keyCode,alt,ctrl,shift}
  let data={}
  data = {
    keyCode:e.keyCode,
    shift:e.shiftKey,
    control:e.ctrlKey,
    alt:e.altKey
  }
  peer.emit('robot','key',data)
}
//监听鼠标输入
window.onmouseup = function(e){
  console.log('鼠标点击')
  //假设data里来的数据是{X，Y，screen：{width，height},video:{width,height}}
  let data={}
  data = {
    X:e.clientX,
    Y:e.clientY,
    video:{
      width:video.getBoundingClientRect().width,
      height:video.getBoundingClientRect().height,
    }
  }
  peer.emit('robot','mouse',data)
}
